import { request } from "@/utils/service"
import { RoleInfo } from "./types/roleinfo"
import { PageData } from "types/pageData"
import { PageQuery } from "types/pageQuery"
import { ApiRole, NumberBothBind } from "types/common-bind"
import { ControllerDescription } from "./types/apiRole"

/**
 * 查询角色分页列表
 * @param data
 * @returns
 */
export async function getRoleList(query: PageQuery): Promise<ApiResponseData<PageData<RoleInfo>>> {
  return request<ApiResponseData<PageData<RoleInfo>>>({
    url: "/api/roleinfo/GetRoleList",
    method: "get",
    params: query
  })
}

/**
 * 创建角色
 * @param data
 * @returns
 */
export async function create(data: RoleInfo): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/roleinfo/Create",
    method: "post",
    data: data
  })
}
/**
 * 更新角色
 * @param data
 * @returns
 */
export async function update(data: RoleInfo): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/roleinfo/Update",
    method: "post",
    data: data
  })
}
/**
 * 删除角色
 * @param params
 * @returns
 */
export async function del(params: any): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/roleinfo/Delete",
    method: "get",
    params: params
  })
}
/**
 * 角色授权菜单
 * @param data 表单数据
 * @returns
 */
export async function roleForMenu(data: NumberBothBind): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/roleinfo/RoleForMenu",
    method: "post",
    data: data
  })
}
/**
 * 用户授权
 * @param data
 * @returns
 */
export async function roleForUser(data: NumberBothBind): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/roleinfo/RoleForUser",
    method: "post",
    data: data
  })
}
/**
 * 取消用户授权
 * @param data
 * @returns
 */
export async function cancelRoleForUser(data: NumberBothBind): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/roleinfo/CancelRoleForUser",
    method: "post",
    data: data
  })
}
/**
 * 获取后端所有的api接口信息
 * @returns
 */
export async function getApiList(): Promise<ApiResponseData<ControllerDescription[]>> {
  return request<ApiResponseData<ControllerDescription[]>>({
    url: "/api/apiRole/getList",
    method: "get"
  })
}
/**
 * 保存角色的api授权信息
 * @param data
 * @returns
 */
export async function saveApi(data: ApiRole): Promise<ApiResponseData<boolean>> {
  return request<ApiResponseData<boolean>>({
    url: "/api/apiRole/save",
    method: "post",
    data: data
  })
}
/**
 * 获取当前角色所拥有api的列表
 * @param params
 * @returns
 */
export async function getRoleApi(params: any): Promise<ApiResponseData<string[]>> {
  return request<ApiResponseData<string[]>>({
    url: "/api/apiRole/getRoleApi",
    method: "get",
    params: params
  })
}
